<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <h1>遥控器页面</h1>
    <button id="btn">测试发送</button>
    <script src="./peerjs.min.js"></script>
    <script>
      const ID = "ctl" + new Date().getTime();
      console.log("ID", ID);
      // 获取按钮
      const btn = document.getElementById("btn");
      btn.addEventListener("click", () => {
        // doing
      });
      function connect() {
        // 创建Peer对象
        const peer = new Peer(ID, {
          host: "localhost",
          port: 9998,
          path: "/web_tv",
        });
        // 监听连接事件
        const conn = peer.connect("tv1703170789601");

        conn.on("open", () => {
          conn.send("hi!");
        });
        // 监听连接事件
        peer.on("open", (id) => {
          console.log("连接成功，ID为：" + id);
        });
        peer.on("connection", (conn) => {
          conn.on("data", (data) => {
            this.setState({
              messages: [...this.state.messages, data],
            });
          });
        });
      }
      connect();
    </script>
  </body>
</html>
